#include "joui.h"
using namespace JOUI;

UIKnobs* m_Knobs[8];
LRESULT CALLBACK OnWndKnoMsgProc(HWND hWnd, LPVOID pWnd, LPVOID UIView, INT uMsg, WPARAM wParam, LPARAM lParam)
{
	auto window = (UIWnd*)pWnd;
	if (uMsg == WM_TIMER)
	{
		float t = GetTime();
		float h = std::fabs(std::sin(t * 0.2f));
		float s = std::fabs(std::sin(t * 0.1f)) * 0.5f + 0.4f;

		UIColor highlight = UIColor::HSV(h, s, 0.75f, 1.0f);
		UIColor base = UIColor::HSV(h, s, 0.5f, 1.0f);
		UIColor lowlight = UIColor::HSV(h, s, 0.2f, 1.0f);
		for (size_t i = 0; i < 8; ++i) {
			m_Knobs[i]->SetColorV(base, lowlight, highlight);
		}
		window->SetShadowColor(base);
		window->SetBorderColor(lowlight);
	}
	return S_OK;
}
LRESULT CALLBACK OnKnoEvent(LPVOID pWnd, LPVOID UIView, INT nID, INT nCode, WPARAM wParam, LPARAM lParam)
{
	auto window = (UIWnd*)pWnd;
	auto obj = (UIKnobs*)UIView;
	if (nCode == WMM_KNOB_VALUE)
	{
		output(obj->GetValue());
	}
	return S_OK;
}
void testknobs(HWND hWnd)
{
	auto window = new UIWnd(0, 0, 610, 420, L"hello Knobs", 0, 0, wws_button_close | wws_button_min | wws_button_max |
		wws_centerwindow | wws_escexit | wws_title | wws_sizeable | wws_moveable, hWnd, NULL, 0, OnWndKnoMsgProc);
	window->SetBackgColor(UIColor(253, 253, 255, 255));
	window->SetBorderColor(UIColor(20, 126, 255, 255));
	window->SetShadowColor(UIColor(20, 126, 255, 155));
	window->SetRadius(10);
	window->SetTimer(100);

	m_Knobs[0] = new UIKnobs(window, 30, 80, 60, 100, L"Gain");
	m_Knobs[0]->SetKnob(0.f, -6.0f, 6.0f, 0.1f, L"%.1fdB", KnobVariant_Tick, KnobFlags_Normal, 10);
	m_Knobs[0]->SetEvent(WMM_KNOB_VALUE, OnKnoEvent);
	//m_Knobs[0]->SetColor(color_border, UIColor(194, 195, 201, 255));

	m_Knobs[1] = new UIKnobs(window, 100, 80, 60, 100, L"Mix");
	m_Knobs[1]->SetKnob(0.f, -1.0f, 1.0f, 0.1f, L"%.1f", KnobVariant_Stepped);
	m_Knobs[1]->SetEvent(WMM_KNOB_VALUE, OnKnoEvent);

	m_Knobs[2] = new UIKnobs(window, 170, 80, 60, 100, L"Pitch");
	m_Knobs[2]->SetKnob(0.f, -6.0f, 6.0f, 0.1f, L"%.1f", KnobVariant_WiperOnly);
	m_Knobs[2]->SetEvent(WMM_KNOB_VALUE, OnKnoEvent);

	m_Knobs[3] = new UIKnobs(window, 240, 80, 60, 100, L"Dry");
	m_Knobs[3]->SetKnob(0.f, -6.0f, 6.0f, 0.1f, L"%.1f", KnobVariant_Stepped, KnobFlags_Normal, 10.f, 10, 1.570796f, 3.141592f);
	m_Knobs[3]->SetEvent(WMM_KNOB_VALUE, OnKnoEvent);

	m_Knobs[4] = new UIKnobs(window, 310, 80, 60, 100, L"Wet");
	m_Knobs[4]->SetKnob(1.f, 1, 10, 0.1f, L"%.1fV", KnobVariant_Stepped, KnobFlags_Normal, 5.f, 20);
	m_Knobs[4]->SetEvent(WMM_KNOB_VALUE, OnKnoEvent);

	m_Knobs[5] = new UIKnobs(window, 380, 80, 60, 100, L"Vertical");
	m_Knobs[5]->SetKnob(6.f, 0.f, 10.f, 0.1f, L"%.1f", KnobVariant_Space, KnobFlags_DragVertical, 1.f, 0);
	m_Knobs[5]->SetEvent(WMM_KNOB_VALUE, OnKnoEvent);

	m_Knobs[6] = new UIKnobs(window, 450, 80, 60, 100, L"Bass");
	m_Knobs[6]->SetKnob(-2.4f, -6.0, 6.0, 0.1f, L"%.1fdB", KnobVariant_Wiper);
	m_Knobs[6]->SetEvent(WMM_KNOB_VALUE, OnKnoEvent);

	m_Knobs[7] = new UIKnobs(window, 520, 80, 60, 100, L"High");
	m_Knobs[7]->SetKnob(4.f, -6.0, 6.0, 0.1f, L"%.1fdB", KnobVariant_WiperDot);
	m_Knobs[7]->SetEvent(WMM_KNOB_VALUE, OnKnoEvent);





	window->Show();
	//window->MessageLoop();
}